// pages/recruit/alreadyTalk/alreadyTalk.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 基本信息
    recruit_info: [],
    user_info: [],
    resume_url: '',
    resume_telephone: '',
    resumes:[],

    // 传参
    anchor_id: '',
    recruit_id: '',
    resume_message_id: '',

    //弹框
    flag_card: true,
    flag_resumes: true,
  },


  //隐藏弹框
  modal_hide() {
    this.setData({
      flag_card: true,
    })
  },
  //卡片、电话 电话沟通
  click_talk() {
    let that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.resume_telephone,
      success(e) {
        console.log("拨打成功")
        that.send_anchor(that.data.anchor_id, that.data.recruit_id, that.data.resume_message_id);
      }
    })
  },

  //会长沟通主播 发送请求
  send_anchor(_anchor_id, _recruit_id, _resume_message_id) {
    wx.request({
      url: app.globalData.url + 'api/guild/link/up/anchor',
      data: {
        token: app.globalData.token,
        anchor_id: _anchor_id,
        recruit_id: _recruit_id,
        resume_message_id: _resume_message_id,
      },
      method: 'POST',
      success: function(e) {
        console.log(e)
      },
    })
  },

  //联系主播
  go_contact(e) {
    console.log(e)
    let that = this;

    let anchor_id = e.currentTarget.dataset.anchor_id;
    let recruit_id = e.currentTarget.dataset.recruit_id;
    let resume_message_id = e.currentTarget.dataset.resume_message_id;
    let resume_url = e.currentTarget.dataset.resume_url;
    let telephone = e.currentTarget.dataset.telephone;
    let resume_id = e.currentTarget.dataset.resume_id;
    let resume_telephone = e.currentTarget.dataset.resume_telephone; //简历电话


    this.setData({
      anchor_id: anchor_id,
      recruit_id: recruit_id,
      resume_message_id: resume_message_id,
      resume_url: resume_url,
      telephone: telephone,
      resume_telephone: resume_telephone, //简历电话

    })

    if (telephone == "") {
      this.setData({
        // flag_card: false,
        // flag_resumes: false,
        // resume_url: resume_url,
      })
      wx.navigateTo({
        url: '../singleRecruit/singleRecruit?resume_id=' + resume_id,
      })
    } else {
      wx.makePhoneCall({
        phoneNumber: telephone,
        success(e) {
          console.log("拨打成功")
          that.send_anchor(this.data.anchor_id, this.data.recruit_id, this.data.resume_message_id);
        }
      })
    }

  },

  //获得会长沟通列表
  get_talkList() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/guild/link/up/list',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: function(e) {
        console.log(e);
        that.setData({
          user_info: e.data.data.list,
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.get_talkList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})